home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK2.toast / Development Kits (Disc 2) / QuickDraw GX / Programming Stuff / Sample Code / Graphics Samples / Perspective Bitmap ƒ / perspective sample.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-15  |  5.1 KB  |  168 lines  |  [TEXT/KAHL]

  1. /*
  2.     perspective bitmap sample code
  3.  
  4.     We will retreive a bitmap from the resource fork of this application. We will convert this bitmap into a bitmap
  5.     shape. This shape will be drawn "normally" and it will be drawn perspected. We collect all of the images into one
  6.     picture. The viewPort attached to the window will be set to a dither level of 4. This will make the drawing to a 
  7.     "gray" monitor look cool.
  8.     
  9.     NOTES:
  10.     • This file requires the following files to run correctly:
  11.         "graphics shell.c", "ColorLibrary.c", "GraphicsDebugLibrary.c",
  12.         "MappingLibrary.c", "PictureLibrary.c", 
  13.         "QDLibrary.c", "ShapeLibrary.c", "TransformLibrary.c".
  14.         
  15.     • This file prints the "best" in landscape mode.
  16.  
  17.     Change History:
  18.  
  19.        4/96    bob        Updated #includes to support changed GX Library names.
  20.                     Updated the note regarding the files needed to run.
  21.                     Updated the copyright date.
  22.  
  23.     ©1990 - 1996 Apple Computer, Inc.
  24.     All rights reserved.
  25. */
  26.  
  27. #include <Events.h>
  28. #include <Windows.h>
  29.  
  30. #include <GXEnvironment.h>
  31. #include "GraphicsLibraries.h"
  32. #include <GXErrors.h>
  33. #include "QDLibrary.h"
  34. #include "graphics shell.h"
  35.  
  36. //
  37. //  Set up the title and size of the window 
  38. //
  39. Rect     gWindowQDRect = {40, 60, 250, 480};
  40. Str255     gWindowTitle = "\pPerspective Sample";
  41.  
  42. //
  43. //    gGraphicsHeapSize sets the size of the graphics gxHeap created by calling the GXNewGraphicsClient routine
  44. //    in main () within graphics shell.c.  You can determine the amount of graphics gxHeap required by using GraphicsBug.
  45. //    With  gGraphicsHeapSize set to 65k, I had 5 free blocks left in the graphics gxHeap. Sounds good to me.
  46. //
  47. //    If we were not dithering the viewPort attached to the window, we would need about 30k for the graphics gxHeap.
  48. //
  49. long        gGraphicsHeapSize = 65;
  50.  
  51. //
  52. //    These gxPolygon structures are used to generate a perspective gxMapping: 
  53. //
  54. long polyA[] = {4, ff(0), ff(0), ff(100), ff(0), ff(100), ff(100), ff(0), ff(100)};    //  100x100 upright
  55. long polyB[] = {4, ff(20), ff(20), ff(60), ff(-20), ff(110), ff(95), ff(5), ff(105)};    //  offset & distorted 
  56.  
  57. gxShape     updateShape;
  58.  
  59.  
  60.  
  61. /*------ CreateImage -----------------------------------------------------------------------------------*/
  62.  
  63. gxShape CreateImage(void);
  64. gxShape CreateImage()
  65. {
  66.     gxShape         bitsShape, shadowShape, image;
  67.     gxTransform     perspector;
  68.     gxRectangle     bounds;
  69.     gxMapping         polyMap;
  70.  
  71.     GXIgnoreGraphicsNotice (transform_already_set);
  72.  
  73.     image = GXNewShape(gxPictureType);
  74.  
  75.     //
  76.     //  Get the bitsShape from the resource file.  If we do not get it, GXValidateShape will drop us into the debugger.
  77.     //
  78.     bitsShape = GetPixMapShape(128);
  79.     GXValidateShape (bitsShape);
  80.  
  81.     GXGetShapeBounds(bitsShape, 0L, &bounds);
  82.     shadowShape = GXNewRectangle(&bounds);
  83.     GXMoveShape(shadowShape, ff(5), ff(5));
  84.     GXSetShapeTransform(shadowShape, GXGetShapeTransform(bitsShape));  
  85.  
  86.     AddToShape(image, shadowShape);
  87.     AddToShape(image, bitsShape);
  88.  
  89.     PolyToPolyMap((gxPolygon *) &polyA, (gxPolygon *) &polyB, &polyMap);
  90.     RotateMapping(&polyMap, ff(23), 0, 0);
  91.  
  92.     perspector = GXNewTransform();
  93.     GXSetTransformMapping(perspector, &polyMap);
  94.     GXMoveTransform(perspector, ff(265), ff(5));
  95.  
  96.     AddToPicture(image, shadowShape, nil, nil, perspector);
  97.     AddToPicture(image, bitsShape, nil, nil, perspector);
  98.  
  99.     GXDisposeShape(shadowShape);
  100.     GXDisposeShape(bitsShape);
  101.     GXDisposeTransform(perspector); 
  102.  
  103.     GXPopGraphicsNotice ();
  104.     
  105.     return image;
  106. }
  107.  
  108.  
  109. /*------ DoInitialization ---------------------------------------------------------------------------------*/
  110.  
  111. void DoInitialization(theWindow)
  112. WindowPtr theWindow;
  113. {
  114.     gxViewPort        windowViewPortParent;
  115.  
  116.     //
  117.     //    Get the viewPort that is attached to the window, and set the dither of this viewPort to 4.  Which
  118.     //    will mean that all objects that are drawn into window will be dithered at a dither level of 4.
  119.     //
  120.      windowViewPortParent = GXGetWindowViewPort(theWindow);
  121.     GXSetViewPortDither(windowViewPortParent, 4);
  122.  
  123.     updateShape = CreateImage();
  124. }
  125.  
  126.  
  127. /*------ DoDraw ---------------------------------------------------------------------------------------*/
  128.  
  129. void DoDraw(theWindow)
  130. WindowPtr theWindow;
  131. {
  132.     GXDrawShape(updateShape);
  133. }
  134.  
  135.  
  136. /*------ DoDispose -------------------------------------------------------------------------------------*/
  137.  
  138. void DoDispose(theWindow)
  139. WindowPtr theWindow;
  140. {
  141.     //  
  142.     //    You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good 
  143.     //    form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
  144.     //    call to DisposeWindow should dispose of the objects. If you are running the debugging version of the 
  145.     //    SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
  146.     //    can turn notices on in this file by setting gDebugging = TRUE (above).
  147.     //
  148.     GXDisposeShape(updateShape);
  149.     GXDisposeShape(gWindowBoundsShape);
  150.        DisposeWindow(theWindow);
  151. }
  152.  
  153.  
  154. /*------ DoClick ---------------------------------------------------------------------------------------*/
  155.  
  156. void DoClick( orgMouseLoc, theWindow )
  157. gxPoint        orgMouseLoc;
  158. WindowPtr     theWindow;
  159. {
  160. }
  161.  
  162.  
  163. /*------ DoIdle -----------------------------------------------------------------------------------------*/
  164.  
  165. void DoIdle(theWindow)
  166. WindowPtr theWindow;
  167. {
  168. }